package com.googlecode.perfectable.visuable.objectbrowser.ui;

import com.googlecode.perfectable.eventable.routing.Sink;
import com.googlecode.perfectable.visuable.objectbrowser.InspectionService;
import com.googlecode.perfectable.visuable.objectbrowser.ObjectRegistration;
import com.googlecode.perfectable.visuable.visual.TabularVisual;
import com.googlecode.perfectable.visuable.visual.controller.Controller;

public class ObjectTableController implements Controller<TabularVisual> {

	private final Sink<ObjectRegistration> sink = new Sink<ObjectRegistration>() {
		@Override
		public void receive(ObjectRegistration event) {
			ObjectTableController.this.registerElement(event.getIdentity(), event.getElement());
		}
	};

	private TabularVisual controlled;

	@Override
	public void takeControl(TabularVisual visual) {
		this.controlled = visual;
	}

	protected void registerElement(Integer identity, Object element) {
		this.controlled.createRow(); // MARK
	}

	public void setInspectionService(InspectionService service) {
		service.listen(this.sink);
	}

}
